package minigame;


import java.awt.event.KeyEvent;

import javax.swing.ImageIcon;


public class Player extends thuoctinh implements commons {
	//lop ve chuyen dong cua nguoi choi
	private final int START_Y = 400; 
    private final int START_X = 350;
    
    private final String ro = "Images/Ro.png";
    private int width;
    
    public Player() {

        ImageIcon ii = new ImageIcon(ro);

        width = ii.getImage().getWidth(null);
        setImage(ii.getImage());
        setX(START_X);
        setY(START_Y);
    }
    
    public void act() {
        x += dx;
        if (x <= 2) 
            x = 2;
        if (x >= BOARD_WIDTH - (width+65)) 
            x = BOARD_WIDTH - (width+65);
    }

    //neu bam mui ten phai, bien dx se de duoc gan gia tri la -2, sau khi ham atc duoc goi , ro se di chuyen sang trai
    public void keyPressed(KeyEvent e) {
        int key = e.getKeyCode();

        if (key == KeyEvent.VK_LEFT)
        {
            dx = -5;
        }

        if (key == KeyEvent.VK_RIGHT)
        {
            dx = 5;
        }

    }

    //khi tha phim ra, ro se khong di chuyen do dx duoc tra ve 0 
    public void keyReleased(KeyEvent e) {
        int key = e.getKeyCode();

        if (key == KeyEvent.VK_LEFT)
        {
            dx = 0;
        }

        if (key == KeyEvent.VK_RIGHT)
        {
            dx = 0;
        }
    }

}
